<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <title>签到</title>
    <script src="../js/plugins/jquery/jquery.min.js"></script>
    <link rel="stylesheet" href="../js/plugins/sign-calc/css/bootstrap3/css/bootstrap.min.css">
    <link rel="stylesheet" href="../js/plugins/sign-calc/css/style.css">
    <link rel="stylesheet" href="../js/plugins/sign-calc/css/qiandao_style.css">
    <link rel="stylesheet" href="/css/myProfiles.css"/>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css"/>
    <script src="../js/plugins/sign-calc/js/calendar.js"></script>
    <script src="/js/plugins/dialog2/dialog.min.js"></script>
    <link rel="stylesheet" href="/js/plugins/dialog2/dialog.css">
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <script>
        $(function () {
            //获取用户的id发送请求
            //从sessionStorage中获取user
            var user = JSON.parse(sessionStorage.getItem("user"));
            console.log(user);
            //获取到用户的id
            var id = user.id;
            //第一次访问页面的时候获取单签时间戳,拼接成"2018-10-"格式发送
            var date = new Date();
            //获取年和月
            var currYear = date.getFullYear();
            var currMoth = date.getMonth() + 1;
            //拼接时间
            var yearAndMoth = currYear + '-' + currMoth + '-';
            $.get("/signs/" + user.id, {yearAndMoth: yearAndMoth}, function (data) {
                //ajax获取日历json数据
                var signList = data;
                calUtil.init(signList);
            })
            //给马上签到一个点击事件提交
            $("#signs").click(function () {
                $.post("/signs/signDay", {userId: user.id}, function (data) {
                    console.log(data);
                    temp = '签到成功';
                    if (data.success) {
                        $(".qdbox").html('<div class="text-center text-green font18"><strong>' + temp + '</strong></div>')
                    } else {
                        $(".qdbox").html('<div class="text-center text-green font18"><strong>' + data.msg + '</strong></div>')

                    }
                })

            })

            function drawIntegral() {
                //发送请求
                $.ajax({
                    async: false,
                    url: "/signs/" + user.id,
                    type: "PUT",
                    dataType: "json",
                    success: function (data) {
                        console.log(data);
                        if (data.success) {
                            //把更新的用户信息重新放到sessionStorage对象中
                            sessionStorage.setItem("user", JSON.stringify(data.result));
                            $(document).dialog({
                                type: 'confirm',
                                style: 'ios',
                                titleShow: false,
                                content: '领取成功',
                                buttonStyle: 'stacked',
                                buttons: [
                                    {
                                        name: '确定',
                                        callback: function () {
                                            window.location.reload();
                                        }
                                    }
                                ]
                            });
                        } else {
                            $(document).dialog({
                                titleShow: false,
                                content: data.msg
                            });
                        }
                    }
                })
            }

            $(".grade").click(function () {
                //拿到天数
                drawIntegral();

            })
            //发送请求判断是否已经领取
            $.get("/signs/state/" + user.id, function (data) {
                console.log(data);
                /*if (data.signNum != 7 ) {
                    $('.btn-lingqu').attr("disabled",true).removeClass("btn-lingqu").addClass("btn-disable");
                }*/
                console.log(user.state == 1);
                if (user.state == 1) {
                    $('.btn-lingqu').attr("disabled", true).removeClass("btn-lingqu").addClass("btn-disable");
                } else {
                    $('.btn-lingqu').attr("disabled", false).removeClass("btn-disable").addClass("btn-lingqu");
                }
            })
        })


        //领取积分按钮

        function signIn() {
            $(".maskbox").fadeIn();
            $(".qdbox").fadeIn();
            $(".maskbox").height($(document).height());
            setTimeout(function () {  //使用  setTimeout（）方法设定定时3000毫秒
                window.location.reload();//页面刷新
            }, 3000);
        }

        $(".maskbox").click(function () {
            $(".maskbox").fadeOut();
            $(".qdbox").fadeOut();
        });

    </script>
</head>
<body>
<div class="nav-search">
    <a href="/mine/profiles.html">
        <span><i class="fa fa-angle-left fa-2x"></i></span>
    </a>
</div>
<hr/>
<div class="container">
    <div class="row">
        <div class="col-xs-12 clearPadding">
            <div class=""><img src="/js/plugins/sign-calc/images/qdBanner.jpg" class="img-responsive"></div>
            <div class="calendar">
                <div class="calenbox">
                    <div id="calendar"></div>
                </div>
                <div class="text-center">
                    <button class="btn btn-qiandao" onClick="signIn()" id="signs">马上签到</button>
                </div>
            </div>
            <div class="padding10">
                <div class="font16 pb10 borderb"><strong>连续签到礼包</strong></div>
                <div class="libaolist">
                    <div class="clearfix borderb ptb10">
                        <div class="col-xs-12 ">
                            签到规则:<br>
                            1.每次签到获取10点骡窝窝欢乐积分.<br>
                            2.连续签到3天可以领取50点骡窝窝欢乐积分.<br>
                            5.签到7天为一个周期.漏签从第一天开始计算<br>
                        </div>
                    </div>
                    <div class="clearfix borderb ptb10">
                        <div class="col-xs-9 clearPadding">
                            <div class="media">
                                <a class="media-left pt3" href="javascript:void(0);">
                                    <img src="../js/plugins/sign-calc/images/dou.png" style="width:30px;height:30px;">
                                </a>
                                <div class="media-body">
                                    <div class="">3天礼包（50骡窝窝欢乐积分）</div>
                                    <div class="text-muted font12">连续签到3天即可领取</div>
                                </div>
                            </div>
                        </div>
                        <div class="col-xs-3 clearPadding text-right pt2">
                            <button class="btn btn-lingqu grade" id="internal">领取</button>
                        </div>
                    </div>
                    <!-- <div class="clearfix borderb ptb10">
                         <div class="col-xs-9 clearPadding">
                             <div class="media">
                                 <a class="media-left pt3" href="javascript:void(0);">
                                     <img src="../js/plugins/sign-calc/images/dou.png" style="width:30px;height:30px;">
                                 </a>
                                 <div class="media-body">
                                     <div class="">5天礼包（70骡窝窝欢乐积分）</div>
                                     <div class="text-muted font12">连续签到5天即可领取</div>
                                 </div>
                             </div>
                         </div>
                         <div class="col-xs-3 clearPadding text-right pt2">
                             <button class="btn btn-lingqu grade" value="5">领取</button>
                         </div>
                     </div>
                     <div class="clearfix borderb ptb10">
                         <div class="col-xs-9 clearPadding">
                             <div class="media">
                                 <a class="media-left pt3" href="javascript:void(0);">
                                     <img src="../js/plugins/sign-calc/images/dou.png" style="width:30px;height:30px;">
                                 </a>
                                 <div class="media-body">
                                     <div class="">7天礼包（100骡窝窝欢乐积分）</div>
                                     <div class="text-muted font12">连续签到7天即可领取</div>
                                 </div>
                             </div>
                         </div>
                         <div class="col-xs-3 clearPadding text-right pt2">
                             <button class="btn btn-lingqu grade" value="7">领取</button>
                         </div>
                     </div>-->
                </div>
            </div>
        </div>
    </div>
</div>
</div>
<div class="maskbox"></div>
<div class="qdbox">

    <!-- <div class="text-center pt10">您已经连续签到&nbsp;<span class="text-green">10</span>&nbsp;天</div>
     <div class="text-center ptb15"><img src="../js/plugins/sign-calc/images/gift.png"
                                         style="width:125px;margin-left:20px;"></div>
     <div class="text-center">
         <button class="btn btn-lottery"><a href="turnlate.html" target="_blank">去抽奖</a></button>
     </div>-->
</div>
<script>

</script>
</body>
</html>
